import { TableRowSelection } from 'antd/es/table/interface';
import { InputProps, ModalProps, ButtonProps, TableProps } from 'antd';
import { ISchema } from '@formily/react';
import { FormPathPattern } from '@formily/core/esm/types';

export type PluginType =
  | 'renderTableCell'
  | 'convertTableSelectedRows'
  | 'convertSearchParams'
  | 'convertDataSource'
  | 'convertDisplayValue'
  | 'tableCheckboxRowProps'
  | 'convertSubmitParams'
  | 'convertDetailValues';

export type TriggerPluginType = string | undefined;

export type TableSelectedRowKeys = TableRowSelection<any>['selectedRowKeys'];
export type TableSelectedRows<T = any> = T[];

export enum RequestMethod {
  POST = 'post',
  GET = 'get',
  DELETE = 'delete',
}

export type ExtraParams = {
  [key: string]: any;
};

export interface FilterDialogProps extends ModalProps, Omit<TableProps<any>, 'footer' | 'title'> {
  isMultiple?: boolean;
  extraSearchParams?: ExtraParams;
  formCode?: string;
  convertSearchType?: string;
  convertTableDataSourceType?: string;
  convertTableSelectedRowsType?: string;
  tableCheckboxRowPropsType?: string;
  url: string;
  method?: RequestMethod;
  schema?: ISchema;
  fieldValidator?: FormPathPattern;
}

export interface InputModalProps<V = any>
  extends Omit<InputProps, 'value' | 'onChange'>,
    Pick<FilterDialogProps, 'url' | 'method'> {
  value?: V;
  onChange?: (value: V) => void;
  dialogProps?: Omit<FilterDialogProps, 'onOk' | 'onCancel' | 'visible' | 'url' | 'method'>;
  convertDisplayValue?: string;
  displayKey?: string;
}

export interface SubmitDialogProps extends ModalProps {
  detailUrl?: string;
  saveUrl: string;
  formCode: string;
  fail?: () => void;
  success?: () => void;
  extraSubmitParams?: ExtraParams;
  fetchDetailParams?: ExtraParams;
  convertSubmitParamsType?: string;
  convertDetailValuesType?: string;
}

export interface ButtonModalProps extends ButtonProps {
  dialogProps?: Omit<SubmitDialogProps, 'onOk' | 'onCancel' | 'visible'>;
  success: () => void;
}

export interface MetaTableItem {
  key: string;
  label: string;
  columnRenderType?: string;
}

export interface ViewDialogProps extends ModalProps {}
